SpatialAverage Module

History

current version 1.4 - 3rd February 2023

version date comment
1.0 02/Dec/2016 Original code
1.1 16/May/2019 added interception and plants dynamic variables
1.2 16/Jun/2021 rewritten to manage new meteo configuration
1.3 18/Jan/2023 module renamed from ArealAverage to SpatialAverage
1.4 03/Feb/2023 modified to not open file if dtoutspatial = 0

License

license: GNU GPL http://www.gnu.org/licenses/

Module Description

routines to compute average value of grid data over a given area For every spatial extent, the average is computed and exported on file of the variables chosen by user in the configuration file. The configuration file includes specific sections for Meteorological input, Soil balance, Snow, Glacier, Canopy interception, Plants, and Sediment erosion and transport variables, as in the examples below.

 epsg = 32632

 Table Start
 Title: mask grids for output
 Id: masks  
 Columns:    [count]  [id]       [name]       [file]    
 Units:       [-]     [-]         [-]           [-]
              1       01        lago      "./bacino_lago.asc"
              2       02     gavardo      "./gavardo.asc"
              3       03     mezzane      "./bacino_mezzane.asc"
              4       04       asola      "./bacino_asola.asc"
 Table End

 [meteo]
  precipitation = 1          # gross precipitation (mm)
  daily-precipitation = 0    # daily precipitation(mm)
  temperature = 1            # air temperature(°C)
  temperature-daily-mean = 1 # mean daily temperature (°C)
  temperature-daily-max = 1  # maximum daily temperature (°C)
  temperature-daily-min = 1  # minimum daily temperature (°C)
  relative-humidity = 0      # air relative humidity (% [0-1])
  solar-radiation = 0        # shortwave radiation (w/m2)
  net-radiation = 0          # net radiation (w/m2)
  wind-speed = 0             # wind speed (m/s)
  irrigation = 0             # irrigation amount (mm)

 [soil-balance]
  soil-moisture = 1  # soil moisture(m3/m3)
  runoff = 1         # runoff(mm)
  infiltration = 1   # infiltration(mm)
  percolation = 1    # percolation(mm)
  actual-ET = 1      # actual evapotranspiration(mm)
  potential-ET = 1   # potential evapotranspiration(mm)
  capillary-rise = 0 # capillary flux(mm)
  error = 1          # balance error (mm)

 [snow]
  rain = 1                  # liquid precipitation(mm)
  snow-water-equivalent = 1 # snow water equivalent(mm)
  melt-coefficient = 1      # snow melt coefficient (mm/day/°C)
  snow-covered-area = 1     # percentage of snow cover (0-1)
  water-in-snow = 1         # water in snowpack (mm)
  snow-melt = 1             # snow melt (mm)

 [glacier]
  ice-water-equivalent = 1 # snow water equivalent(mm)
  ice-covered-area = 1     # percentage of glacial cover (0-1)
  water-in-ice = 1         # water in glaciers (mm)
  ice-melt = 1             # ice melt (mm)

 [sediment]
  detachment-rate = 0  # eroded sediment amount (kg)

 [canopy]
  canopy-storage = 0   # canopy water storage (mm)
  throughfall = 0      # canopy throughfall (mm)
  transpiration = 0    # canopy transpiration (mm)

 [plants]
  lai = 0        # leaf area index (m2/m2)
  gpp = 0        # gross primary production (t)
  npp = 0        # net primary production (t)
  stem = 0       # stem mass (t)
  root = 0       # root mass (t)
  leaf = 0       # leaf mass (t)
  cover = 0      # canopy cover (0-1)
  dbh = 0        # plant diameter at brest height (cm)
  height = 0     # plant heigth (m)
  density = 0    # plant density (tree/hectare)
  stem-yield = 0 # stem yield (t)

The value is computed for all variables marked with 1. When one variable is marked by 1 but it is not allocated because not computed by the FEST model according to options defined in the configuration files, value is not exported. For example, if user set to export wind speed in the meteorological section but wind speed is not used in the current simulation, values of wind speed are not written in the output file. The name of output files is the concatenation of result folder name defined in the main configuration file , the name of the spatial extent , and a suffix recalling the process related to the variables, as listed in the following table.

variables Output file name
meteorological <folder> <name> _meteo.out
soil balance <folder> <name> _balance.out
snow <folder> <name> _snow.out
glaciers <folder> <name> _glaciers.out
sediment <folder> <name> _sediment.out
canopy <folder> <name> _canopy.out
plants <folder> <name> _plants.out


Variables

Type Visibility Attributes Name Initial
character(len=30), public :: balanceheader(10) = (/'soil-moisture', 'soil-moisture-rz', 'soil-moisture-tz', 'runoff_mm', 'infiltration_mm', 'percolation_mm', 'actual_ET_mm', 'PET_mm', 'capillary-rise_mm', 'error_mm'/)
logical, public :: balanceout(10)
character(len=30), public :: canopyheader(3) = (/'canopy-storage_mm', 'throughfall_mm', 'canopy-transpiration_mm'/)
logical, public :: canopyout(3)
character(len=30), public :: iceheader(4) = (/'ice-water-equivalent_mm', 'glacier-covered-area_0-1', 'water-in-ice_mm', 'ice-melt_mm'/)
logical, public :: iceout(4)
character(len=40), public :: meteoheader(11) = (/'precipitation_mm', 'precipitation_daily_mm', 'air-temperature_Celsius', 'air-temperature-daily-mean_Celsius', 'air-temperature-daily-max_Celsius', 'air-temperature-daily-min_Celsius', 'relative-humidity_0-100', 'solar-radiation_wm-2', 'net-radiation_wm-2', 'wind-speed_ms-1', 'irrigation_mm'/)
logical, public :: meteoout(11)
character(len=30), public :: plantsheader(11) = (/'LAI', 'GPP_t', 'NPP_t', 'stem-mass_t', 'root-mass_t', 'leaf-mass_t', 'canopy-cover_0-1', 'DBH_cm', 'Height_m', 'density_tree-per-hectare', 'stem-yield_t'/)
logical, public :: plantsout(11)
character(len=30), public :: sedimentheader(1) = (/'erosion_kg'/)
logical, public :: sedimentout(1)
character(len=30), public :: snowheader(6) = (/'liquid-precipitation_mm', 'snow-water-equivalent_mm', 'melt-coefficient_mm/day/C', 'snow-covered-area_01', 'water-in-snow_mm', 'snow-melt_mm'/)
logical, public :: snowout(6)
type(DateTime), public :: timeSpatialAverageBalance
type(DateTime), public :: timeSpatialAverageCanopy
type(DateTime), public :: timeSpatialAverageIce
type(DateTime), public :: timeSpatialAverageMeteo
type(DateTime), public :: timeSpatialAveragePlants
type(DateTime), public :: timeSpatialAverageSediment
type(DateTime), public :: timeSpatialAverageSnow
logical, private :: balanceInitialized = .FALSE.
logical, private :: canopyInitialized = .FALSE.
integer(kind=short), private :: countbalance

count number of soil balance variables active for output

integer(kind=short), private :: countcanopy

count number of canopy variables active for output

integer(kind=short), private :: countice

count number of glaciers variables active for output

integer(kind=short), private :: countmeteo

count number of meteo variables active for output

integer(kind=short), private :: countplants

count number of plants variables active for output

integer(kind=short), private :: countsediment

count number of sediment variables active for output

integer(kind=short), private :: countsnow

count number of snow variables active for output

type(Table), private :: extent_table
type(Extent), private, ALLOCATABLE :: extents(:)
logical, private :: iceInitialized = .FALSE.
logical, private :: meteoInitialized = .FALSE.
integer(kind=short), private :: nextents
logical, private :: plantsInitialized = .FALSE.
logical, private :: sedimentInitialized = .FALSE.
logical, private :: snowInitialized = .FALSE.

Derived Types

type, public ::  Extent

Components

Type Visibility Attributes Name Initial
real(kind=float), public :: area

surface area (m2)

real(kind=float), public, ALLOCATABLE :: balance(:)
real(kind=float), public, ALLOCATABLE :: canopy(:)
character(len=1000), public :: filebalance
character(len=1000), public :: filecanopy
character(len=1000), public :: fileice
character(len=1000), public :: filemeteo
character(len=1000), public :: fileplants
character(len=1000), public :: filesediment
character(len=1000), public :: filesnow
real(kind=float), public, ALLOCATABLE :: ice(:)
character(len=100), public :: id
type(grid_integer), public :: mask
real(kind=float), public, ALLOCATABLE :: meteo(:)
character(len=100), public :: name
real(kind=float), public, ALLOCATABLE :: plants(:)
real(kind=float), public, ALLOCATABLE :: sediment(:)
real(kind=float), public, ALLOCATABLE :: snow(:)
integer(kind=short), public :: unitbalance
integer(kind=short), public :: unitcanopy
integer(kind=short), public :: unitice
integer(kind=short), public :: unitmeteo
integer(kind=short), public :: unitplants
integer(kind=short), public :: unitsediment
integer(kind=short), public :: unitsnow

Subroutines

public subroutine ComputeSpatialAverageBalance(dt, sm, smrz, smtz, runoff, infrate, perc, et, pet, caprise, error)

Compute spatial average of soil water balance variables

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: dt

time step (s)

type(grid_real), intent(in) :: sm

mean soil moisture (m3/m3)

type(grid_real), intent(in) :: smrz

root zone soil moisture (m3/m3)

type(grid_real), intent(in) :: smtz

transmission zone soil moisture (m3/m3)

type(grid_real), intent(in) :: runoff

runoff rate (m/s)

type(grid_real), intent(in) :: infrate

infiltration rate (m/s)

type(grid_real), intent(in) :: perc

percolation (m/s)

type(grid_real), intent(in) :: et

actual evapotranspiration rate (m/s)

type(grid_real), intent(in) :: pet

potential evapotranspiration rate (m/s)

type(grid_real), intent(in) :: caprise

actual evapotranspiration rate (m/s)

type(grid_real), intent(in) :: error

balance error (mm)

public subroutine ComputeSpatialAverageCanopy(dt, canopyStorage, throughfall, pt)

Compute spatial average of canopy interception variables

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: dt

time step (s)

type(grid_real), intent(in) :: canopyStorage

water canopy storage (mm)

type(grid_real), intent(in) :: throughfall

effective rain reaching soil surface (m/s)

type(grid_real), intent(in) :: pt

potential transpiration from canopy (m/s)

public subroutine ComputeSpatialAverageGlaciers(dt, iwe, water, iceMelt)

Compute spatial average of glaciers variables

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: dt

time step (s)

type(grid_real), intent(in) :: iwe

ice water equivalent (m)

type(grid_real), intent(inout) :: water

free water in ice (m)

type(grid_real), intent(in) :: iceMelt

ice melt in the time step (m)

public subroutine ComputeSpatialAverageMeteo(dt, temp, tmean, tmax, tmin, precipitation, rh, radiation, netradiation, windspeed, daily_precipitation, irrigation)

Compute spatial average of meteorological variables

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: dt

time step (s)

type(grid_real), intent(in) :: temp

air temperarure (°C)

type(grid_real), intent(in) :: tmean

air temperarure daily mean(°C)

type(grid_real), intent(in) :: tmax

air temperarure daily max (°C)

type(grid_real), intent(in) :: tmin

air temperarure daily min (°C)

type(grid_real), intent(in) :: precipitation

precipitation rate (m/s)

type(grid_real), intent(in) :: rh

air relative humidity (0-100)

type(grid_real), intent(in) :: radiation

solar radiation (w/m2)

type(grid_real), intent(in) :: netradiation

net radiation (w/m2)

type(grid_real), intent(in) :: windspeed

wind speed (m/s)

type(grid_real), intent(in) :: daily_precipitation

daily precipitation (m/s)

type(grid_real), intent(in) :: irrigation

irrigation rate (m/s)

public subroutine ComputeSpatialAveragePlants(dt, lai, gpp, npp, stem, root, leaf, cover, dbh, height, density, stemyield)

Compute spatial average of plants variables

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: dt

time step (s)

type(grid_real), intent(in) :: lai

leaf area index (m2/m2)

type(grid_real), intent(in) :: gpp

gross primary production (t)

type(grid_real), intent(in) :: npp

net primary production (t)

type(grid_real), intent(in) :: stem

stem biomass (t)

type(grid_real), intent(in) :: root

root biomass (t)

type(grid_real), intent(in) :: leaf

foliage biomass (t)

type(grid_real), intent(in) :: cover

canopy cover (0-1)

type(grid_real), intent(in) :: dbh

diameter at brest heigth (cm)

type(grid_real), intent(in) :: height

tree height (m)

type(grid_real), intent(in) :: density

tree density (tree/hectare)

type(grid_real), intent(in) :: stemyield

stem yield (t)

public subroutine ComputeSpatialAverageSediment(dt, erosion)

Compute spatial average of sediment variables

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: dt

time step (s)

type(grid_real), intent(in) :: erosion

interril sediment detachment rate (kg/s)

public subroutine ComputeSpatialAverageSnow(dt, rain, swe, meltCoeff, freeWater, snowMelt)

Compute spatial average of snow variables

Arguments

Type IntentOptional Attributes Name
integer(kind=short), intent(in) :: dt

time step (s)

type(grid_real), intent(in) :: rain

liquid precipitation rate (m/s)

type(grid_real), intent(in) :: swe

snow water equivalent (m)

type(grid_real), intent(in) :: meltCoeff

melt coefficient (mm/day/°C)

type(grid_real), intent(in) :: freeWater

liquid water in snow (m)

type(grid_real), intent(in) :: snowMelt

snow melt (m)

public subroutine ExportSpatialAverageBalance(init)

Export spatial average of soil balance variables

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: init

public subroutine ExportSpatialAverageCanopy(init)

Export spatial average of canopy interception variables

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: init

public subroutine ExportSpatialAverageGlaciers(init)

Export spatial average of glaciers variables

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: init

public subroutine ExportSpatialAverageMeteo(init)

Export spatial average of meteorological variables

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: init

public subroutine ExportSpatialAveragePlants(init)

Export spatial average of plants variables

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: init

public subroutine ExportSpatialAverageSediment(init)

Export spatial average of sediment variables

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: init

public subroutine ExportSpatialAverageSnow(init)

Export spatial average of snow variables

Arguments

Type IntentOptional Attributes Name
logical, intent(in), optional :: init

public subroutine InitSpatialAverageBalance(fileini, pathout, sm, smrz, smtz, runoff, infrate, perc, et, pet, caprise, error)

Initialization of spatial average of soil balance variables

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileini
character(len=*), intent(in) :: pathout
type(grid_real), intent(in) :: sm

mean soil moisture (m3/m3)

type(grid_real), intent(in) :: smrz

root zone soil moisture (m3/m3)

type(grid_real), intent(in) :: smtz

transmission moisture (m3/m3)

type(grid_real), intent(in) :: runoff

runoff rate (m/s)

type(grid_real), intent(in) :: infrate

infiltration rate (m/s)

type(grid_real), intent(in) :: perc

percolation (m/s)

type(grid_real), intent(in) :: et

actual evapotranspiration rate (m/s)

type(grid_real), intent(in) :: pet

potential evapotranspiration rate (m/s)

type(grid_real), intent(in) :: caprise

actual evapotranspiration rate (m/s)

type(grid_real), intent(in) :: error

balance error (mm)

public subroutine InitSpatialAverageCanopy(fileini, pathout, canopyStorage, throughfall, pt)

Initialization of spatial average of canopy interception variables

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileini
character(len=*), intent(in) :: pathout
type(grid_real), intent(in) :: canopyStorage

water canopy storage (mm)

type(grid_real), intent(in) :: throughfall

effective rain reaching soil surface (m/s)

type(grid_real), intent(in) :: pt

potential transpiration from canopy (m/s)

public subroutine InitSpatialAverageGlaciers(fileini, pathout, iwe, freeWater, iceMelt)

Initialization of spatial average of glaciers variables

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileini
character(len=*), intent(in) :: pathout
type(grid_real), intent(in) :: iwe

ice water equivalent (m)

type(grid_real), intent(in) :: freeWater

water in ice (m)

type(grid_real), intent(in) :: iceMelt

ice melt in the time step (m)

public subroutine InitSpatialAverageMeteo(fileini, pathout, temp, tmean, tmax, tmin, precipitation, rh, radiation, netradiation, windspeed, daily_precipitation, irrigation)

Initialization of spatial average of meteorological variables

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileini
character(len=*), intent(in) :: pathout
type(grid_real), intent(in) :: temp

air temperarure (°C)

type(grid_real), intent(in) :: tmean

air temperarure daily mean(°C)

type(grid_real), intent(in) :: tmax

air temperarure daily max (°C)

type(grid_real), intent(in) :: tmin

air temperarure daily min (°C)

type(grid_real), intent(in) :: precipitation

precipitation rate (m/s)

type(grid_real), intent(in) :: rh

air relative humidity (0-100)

type(grid_real), intent(in) :: radiation

solar radiation (w/m2)

type(grid_real), intent(in) :: netradiation

net radiation (w/m2)

type(grid_real), intent(in) :: windspeed

wind speed (m/s)

type(grid_real), intent(in) :: daily_precipitation

daily precipitation rate (m/s)

type(grid_real), intent(in) :: irrigation

irrigation rate (m/s)

public subroutine InitSpatialAveragePlants(fileini, pathout, lai, gpp, npp, stem, root, leaf, cover, dbh, height, density, stemyield)

Initialization of spatial average of plants dynamic variables

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileini
character(len=*), intent(in) :: pathout
type(grid_real), intent(in) :: lai

leaf area index (m2/m2)

type(grid_real), intent(in) :: gpp

gross primary production (t)

type(grid_real), intent(in) :: npp

net primary production (t)

type(grid_real), intent(in) :: stem

stem biomass (t)

type(grid_real), intent(in) :: root

root biomass (t)

type(grid_real), intent(in) :: leaf

foliage biomass (t)

type(grid_real), intent(in) :: cover

canopy cover (0-1)

type(grid_real), intent(in) :: dbh

diameter at brest heigth (cm)

type(grid_real), intent(in) :: height

tree height (m)

type(grid_real), intent(in) :: density

tree density (tree/hectare)

type(grid_real), intent(in) :: stemyield

stem yield (t)

public subroutine InitSpatialAverageSediment(fileini, pathout, detrate)

Initialization of spatial average of sediment variables

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileini
character(len=*), intent(in) :: pathout
type(grid_real), intent(in) :: detrate

sediment detachment rate (kg/s)

public subroutine InitSpatialAverageSnow(fileini, pathout, rain, swe, meltCoeff, freeWater, snowMelt)

Initialization of spatial average of snow variables

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileini
character(len=*), intent(in) :: pathout
type(grid_real), intent(in) :: rain

rainfall rate (m/s)

type(grid_real), intent(in) :: swe

snow water equivalent (m)

type(grid_real), intent(in) :: meltCoeff

snow melt coefficient (mm/day/C)

type(grid_real), intent(in) :: freeWater

water in snow pack (m)

type(grid_real), intent(in) :: snowMelt

snow melt i the time step (m)

private subroutine ConfigureExtents(fileini, pathout)

Configure extents for computing and storing spatial average values

Arguments

Type IntentOptional Attributes Name
character(len=*), intent(in) :: fileini
character(len=*), intent(in) :: pathout